package com.neuedu.springmvc.controller;

import com.neuedu.springmvc.po.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

/**
 * @author 金山
 * 项目：springmvc-learn
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2025/3/1714:35
 */
@Controller
    @RequestMapping("/result")
public class ReturnController {


    /**
     * http://localhost:8080/web/result/req1
     * @return  默认返回Sting字符串的时候  代表视图名称   jsp    index 可以使用  重定向 和内部跳转
     */
    @RequestMapping("/req1")
    public String req1(HttpServletRequest request ){
        return "/index.jsp";
    }

    // /**
    //  * http://localhost:8080/web/result/req1
    //  * @return  默认返回Sting字符串的时候  代表视图名称   jsp    index 可以使用  重定向 和内部跳转
    //  */
    // @RequestMapping("/req2")
    // public String req2(HttpServletRequest request ){
    //     return "redirect:/index.jsp";
    // }
    // /**
    //  * http://localhost:8080/web/result/req1
    //  * @return  默认返回Sting字符串的时候  代表视图名称   jsp    index 可以使用  重定向 和内部跳转
    //  */
    // @RequestMapping("/req3")
    // public String req3(HttpServletRequest request ){
    //     return "forward:/index.jsp";
    // }


    @ResponseBody
    @RequestMapping("/req4")
    public String req4( ){


        User user = new User();
        user.setUsername("admin");
        user.setPassword("1234567");

        return "{\"name\":\""+user.getUsername()+"\",\"age\":19}";
    }

    @ResponseBody
    @RequestMapping("/req5")
    public User req5( ){
        User user = new User();
        user.setUsername("admin");
        user.setPassword("1234567");

        user.setBirthday(new Date());

        return user;
    }

    @ResponseBody
    @RequestMapping("/req6")
    public List<User> req6( ){
        List userList = new ArrayList();
        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setUsername("admin");
            user.setPassword("1234567");
            userList.add(user);

        }
        return userList;
    }

    @ResponseBody
    @RequestMapping("/req7")
    public Map req7( ){

        Map info = new HashMap();


        info.put("name","张飞");
        info.put("age",20);

        return info;
    }



    @ResponseBody
    @RequestMapping("/req8")
    public Set<User> req8( ){
        Set userSet = new HashSet();
        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setUsername("admin");
            user.setPassword("1234567");
            userSet.add(user);

        }
        return userSet;
    }


}
